<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="企业名称" prop="crewName">
          <el-input
            v-model="queryParams.crewName"
            placeholder="请输入企业名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item :offset="10">
         <!--<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>-->
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="resumeList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" type="index" />
        <el-table-column label="提交时间" align="center" width="100" >
            <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
        </el-table-column>
        <el-table-column label="企业名称" align="center" prop="enterpriseName"></el-table-column>
        <el-table-column label="招聘职务" align="center" >
            <template slot-scope="scope">
                <dict-tag :options="dict.type.duties" :value="scope.row.recruitDuties"/>
            </template>
          </el-table-column>
        <!-- <el-table-column label="招聘数量" align="center" prop="recruitNumber" /> -->
        <el-table-column label="国籍" align="center" prop="crewLocation"/>
          <el-table-column label="船型" align="center" >
            <template slot-scope="scope">
                <dict-tag :options="dict.type.ships_type" :value="scope.row.shippingType"/>
            </template>
          </el-table-column>
          <el-table-column label="航区" align="center" prop="navigationArea" />
          <el-table-column label="载重吨" align="center" prop="deadweightTon" />
          <!-- <el-table-column label="性别" align="center">
            <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender"/>
            </template>
          </el-table-column>
          <el-table-column label="年龄" align="center" prop="age" /> -->
          <el-table-column label="建造年份" align="center" prop="yearOfConstruction" >
            <template slot-scope="scope">
                {{ scope.row.yearOfConstruction ? parseTime(scope.row.yearOfConstruction, '{y}') : '' }}
            </template>
          </el-table-column>
          <el-table-column label="到岗时间" align="center" prop="onDutyTime"  >
            <template slot-scope="scope">
                {{ scope.row.onDutyTime ? parseTime(scope.row.onDutyTime) : '' }}
            </template>
          </el-table-column>
          <el-table-column label="招聘说明" align="center" prop="recruitIllustrate" />
<!--          <el-table-column label="是否发布" align="center" prop="isPublish" :formatter="formatIsPublish" />-->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDetail(scope.row)"
              v-hasPermi="['system:resume:detail']"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:resume:remove']"
            >删除</el-button>
<!--            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="changeStatus(scope.row)"
              v-hasPermi="['system:recruit:controlPublish']"
            >{{scope.row.isPublish=='0'?'通过':'驳回'}}</el-button>-->
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改船员简历对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px" disabled>
          <!-- <el-form-item label="注册时间" prop="crewName">
          </el-form-item>
          <el-form-item label="企业名称" prop="crewStatus">
          </el-form-item> -->
          <el-form-item label="招聘职务" prop="crewLocation">
            <el-select  placeholder="请选择招聘职务" v-model="form.recruitDuties">
                <el-option
                    v-for="dict in dict.type.duties"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value">
                </el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="招聘数量" prop="recruitNumber">
            <el-input v-model="form.recruitNumber" placeholder="请输入招聘数量" />
          </el-form-item> -->
          <el-form-item label="国籍" prop="crewLocation">
            <el-input v-model="form.crewLocation" placeholder="请输入国籍" />
          </el-form-item>
          <el-form-item label="船型" prop="shippingType">
            <el-select  placeholder="请选择船型" v-model="form.shippingType">
                <el-option
                    v-for="dict in dict.type.ships_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    >
                </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="航区" prop="navigationArea">
            <el-input v-model="form.navigationArea" placeholder="请输入航区" />
          </el-form-item>
          <el-form-item label="载重吨" prop="deadweightTon">
            <el-input v-model="form.deadweightTon" placeholder="请输入载重吨" />
          </el-form-item>
          <el-form-item label="建造年份" prop="yearOfConstruction">
            <el-date-picker
              v-model="form.yearOfConstruction"
              type="year"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="到岗时间" prop="onDutyTime">
            <el-date-picker
              v-model="form.onDutyTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <!-- <el-form-item label="性别" prop="gender">
            <el-input v-model="form.gender" placeholder="请输入性别" />
          </el-form-item>
          <el-form-item label="年龄" prop="age">
            <el-input v-model="form.age" placeholder="请输入年龄" />
          </el-form-item> -->
          <el-form-item label="招聘说明" prop="recruitIllustrate">
            <el-input v-model="form.recruitIllustrate" placeholder="请输入招聘说明" type="textarea" :rows="8"/>
          </el-form-item>
          <!-- <el-form-item label="备注" prop="professionalSkills">
            <el-input v-model="form.professionalSkills" placeholder="请输入备注" type="textarea"/>
          </el-form-item> -->
  <!--        <el-form-item label="头像图片" prop="headshotId">
            <el-input v-model="form.headshotId" placeholder="请输入头像图片" />
          </el-form-item>
          <el-form-item label="证书图片" prop="certificatesId">
            <el-input v-model="form.certificatesId" placeholder="请输入证书图片" />
          </el-form-item>-->
          <el-form-item label="招聘单位" prop="deadweightTon">
            <el-input v-model="form.recruitOrgan" placeholder="请输入招聘单位" />
          </el-form-item>
          <el-form-item label="联系人" prop="deadweightTon">
            <el-input v-model="form.recruitContacts" placeholder="请输入联系人" />
          </el-form-item>
          <el-form-item label="联系电话" prop="recruitContactsPhone">
            <el-input v-model="form.recruitContactsPhone" placeholder="请输入联系电话" />
          </el-form-item>
          <el-form-item label="邮箱" prop="recruitContactsEmail">
            <el-input v-model="form.recruitContactsEmail" placeholder="请输入邮箱" />
          </el-form-item>
        </el-form>
        <!--<div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>-->
      </el-dialog>
    </div>
  </template>

  <script>
  import { listRecuit, getRecuit, delRecuit, addRecuit, updateRecuit, isOrNotPublish } from "@/api/system/recruit";

  export default {
    name: "Resume",
    dicts: ['ships_type', 'duties', 'sys_user_sex'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 船员简历表格数据
        resumeList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          crewName: null,
        },
        // 表单参数
        form: {
            recruitDuties:null,
            recruitNumber:null,
            crewLocation:null,
            shippingType:null,
            deadweightTon:null,
            navigationArea:null,
            gender:null,
            age:null,
            createTime:null,
            recruitIllustrate:null,
        },
        // 表单校验
        rules: {
        },
        diaType: ''
      };
    },
    created() {
      this.getList();
    },
    methods: {
      formatIsPublish: function (row, column, cellValue, index) {
        return row.isPublish == '1' ? '是' : '否';
      },
      /** 查询船员简历列表 */
      getList() {
        this.loading = true;
        listRecuit(this.queryParams).then(response => {
          this.resumeList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
            id: null,
            recruitDuties:null,
            recruitNumber:null,
            crewLocation:null,
            shippingType:null,
            deadweightTon:null,
            navigationArea:null,
            gender:null,
            age:null,
            recruitIllustrate:null,
            createTime:null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.diaType = 'add'
        this.open = true;
        this.title = "新增招聘信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.diaType = 'edit'
        const id = row.id || this.ids
        getRecuit(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改招聘信息";
        });
      },
      /** 详情按钮 */
      handleDetail(row) {
        this.reset();
        this.diaType = 'detail'
        const id = row.id || this.ids
        getRecuit(id).then(response => {
          this.form = response.data;
          // this.form.birthDate = new Date(parseInt(this.form.birthDate) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ')
          this.form.yearOfConstruction = this.form.yearOfConstruction ? this.form.yearOfConstruction * 1000 : null
          this.form.onDutyTime = this.form.onDutyTime ? this.form.onDutyTime * 1000 : null
          this.open = true;
          this.title = "船员简历详情";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateRecuit(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
                this.form.createTime=this.parseTime(new Date().getTime())
              addRecuit(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除招聘信息？').then(function() {
          return delRecuit(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/crewResume/export', {
          ...this.queryParams
        }, `resume_${new Date().getTime()}.xlsx`)
      },
      changeStatus(row){
        this.$confirm(`确定要${row.isPublish=='0'?'通过':'驳回'}吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          isOrNotPublish({id:row.id}).then((res)=>{
            this.$message({
              type: 'success',
              message: '操作成功'
            });
            this.getList()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消'
          });
        });
      },
    }
  };
  </script>
